﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using GroupChat2013.Service;
using GroupChat2013.Entity;
using GroupChat2013.Common;
using System.IO;

namespace GroupChat2013.Logic.Message
{
    /// <summary>
    /// 聊天信息中的图片上传下载基类
    /// </summary>
    public abstract class AbstractImageUpload
    {
        protected ServiceUrlProxy urlProxy = ServiceUrlProxy.GetInstance();
        protected UserInfo m_UserInfo;

        private const string Extension = ".gif";
        
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="userInfo"></param>
        public AbstractImageUpload(UserInfo userInfo)
        {
            m_UserInfo = userInfo;
        }

        /// <summary>
        /// 上传消息中嵌入的图片信息
        /// </summary>
        /// <param name="imageList">图片路径数组</param>
        public void ImageUpload(List<string> imageList)
        {
            if (imageList == null || imageList.Count == 0)
                return;

            string path = "";
            //如果消息中有图片，则添加图片
            imageList.ForEach(name =>
            {
                path = Path.Combine(EngineContext.Current.FilePathManager.ImagePath, name + Extension);
                UpLoadImage(path);
            });
        }

        /// <summary>
        /// 上传图片
        /// </summary>
        /// <param name="localUrl">图片本地路径</param>
        /// <returns></returns>
        public abstract string UpLoadImage(string localUrl);

        /// <summary>
        /// 下载图片
        /// </summary>
        /// <param name="imageMD5Name">图片名称</param>
        /// <param name="savePath">保存路径</param>
        public abstract void DownlodImage(string imageMD5Name, string savePath);

    }
}
